|
|
|
|
|
|
|
Then the error equation is: |
|
|
|
 |
|
|
|
|
E = S (yi - (A0 + A1 * xi + A2 * xi2 + ... + AN * xiN))2 |
|
|
|
|
|
|
|
|
Following the methods of the previous sections, you take the partial derivatives of this equation with respect to the constants A1, A2, . . ., AN. For example, the partial derivative with respect to Aj is: |
|
|
|
 |
|
|
|
|
dE/dAj = S -2 * (yi - (A0 + A1 * xi + ... + AN * xiN)) * (xij)
= -2 * S (xij * yi - A0 * xij - A1 * xij+1 - ... - AN * xij+N) |
|
|
|
|
|
|
|
|
If you set this equation equal to zero, divide both sides of the equation by 2, and rearrange a little, you get: |
|
|
|
 |
|
|
|
|
A0 * S xij + A1 * S xij+1 + ... + AN * S xij+N = S (xij * yi) |
|
|
|
|
|
|
|
|
This mess seems more complicated than the equations in the previous sections, but it is not really too different. Remember that the xi and yi are the data values you are trying to fit. The only unknowns in these equations are the Ai values. That means all the summations are simple numeric values you can calculate using the data points. Then the ith equation simplifies to: |
|
|
|
 |
|
|
|
|
A0 * Ci0 + A1 * Ci1 + ... + AN * CiN = CN+1 |
|
|
|
|
|
|
|
|
If you calculate all the partial derivatives and set them all equal to zero, you have N + 1 equations and N + 1 unknowns. You can solve the equations to find the Ai values. |
|
|
|
|
|
|
|
|
The previous sections solved systems of two and three equations directly. To solve a system of an unknown number of equations, you need a more systematic approach. You can do this using Gaussian elimination. |
|
|
|
|
|
|
|
|
First, place the equations' coefficients in a two-dimensional array. Each row in the array corresponds to an equation. Each column corresponds to the coefficients of an Ai value. The entries in the array look like this: |
|
|
|
|
|
|
|
|
The first step in Gaussian elimination is to divide each value in the first row by the value in the upper left corner C00. Dividing every entry by the same value keeps the meaning of the system of equations unchanged. The solution to the new equations is the same as |
|
|
|
|
|